const app = getApp()
Page({
  data: {
    avatar: '',
    nickName: ''
  },
  onShow () {
    const app = getApp()
    app.token && this.getUser()
    console.log(app)
    this.setData({ avatar: app.avatar, nickName: app.nickName })
  },
  async getUser () {
    const {
      code,
      data: { avatar, nickName }
    } = await wx.http.get('/userInfo')
    // 检测接口是否正常返回结果
    if (code !== 10000) return wx.utils.toast()
    // 渲染数据
    this.setData({ avatar, nickName })
    app.setApp('avatar', avatar)
    app.setApp('nickName', nickName)
  }
})
